/*
  * Copyright (c) 2025 Huawei Device Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
    *
  * http://www.apache.org/licenses/LICENSE-2.0
    *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * */

// automatically generated by the FlatBuffers compiler, do not modify

/* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */

import * as flatbuffers from '@ohos/flatbuffers';

import { EventType } from '../notification/event-type.js';
import { EventUnion, unionToEventUnion, unionListToEventUnion } from '../notification/event-union.js';


export class EventLog {
  bb: flatbuffers.ByteBuffer|null = null;
  bb_pos = 0;
  __init(i:number, bb:flatbuffers.ByteBuffer):EventLog {
  this.bb_pos = i;
  this.bb = bb;
  return this;
}

static getRootAsEventLog(bb:flatbuffers.ByteBuffer, obj?:EventLog):EventLog {
  return (obj || new EventLog()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

static getSizePrefixedRootAsEventLog(bb:flatbuffers.ByteBuffer, obj?:EventLog):EventLog {
  bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
  return (obj || new EventLog()).__init(bb.readInt32(bb.position()) + bb.position(), bb);
}

timestamp():bigint {
  const offset = this.bb!.__offset(this.bb_pos, 4);
  return offset ? this.bb!.readInt64(this.bb_pos + offset) : BigInt('0');
}

eventType():EventType {
  const offset = this.bb!.__offset(this.bb_pos, 6);
  return offset ? this.bb!.readUint8(this.bb_pos + offset) : EventType.Unknown;
}

eventDataType():EventUnion {
  const offset = this.bb!.__offset(this.bb_pos, 8);
  return offset ? this.bb!.readUint8(this.bb_pos + offset) : EventUnion.NONE;
}

eventData<T extends flatbuffers.Table>(obj:any):any|null {
  const offset = this.bb!.__offset(this.bb_pos, 10);
  return offset ? this.bb!.__union(obj, this.bb_pos + offset) : null;
}

static startEventLog(builder:flatbuffers.Builder) {
  builder.startObject(4);
}

static addTimestamp(builder:flatbuffers.Builder, timestamp:bigint) {
  builder.addFieldInt64(0, timestamp, BigInt('0'));
}

static addEventType(builder:flatbuffers.Builder, eventType:EventType) {
  builder.addFieldInt8(1, eventType, EventType.Unknown);
}

static addEventDataType(builder:flatbuffers.Builder, eventDataType:EventUnion) {
  builder.addFieldInt8(2, eventDataType, EventUnion.NONE);
}

static addEventData(builder:flatbuffers.Builder, eventDataOffset:flatbuffers.Offset) {
  builder.addFieldOffset(3, eventDataOffset, 0);
}

static endEventLog(builder:flatbuffers.Builder):flatbuffers.Offset {
  const offset = builder.endObject();
  return offset;
}

static finishEventLogBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
  builder.finish(offset);
}

static finishSizePrefixedEventLogBuffer(builder:flatbuffers.Builder, offset:flatbuffers.Offset) {
  builder.finish(offset, undefined, true);
}

static createEventLog(builder:flatbuffers.Builder, timestamp:bigint, eventType:EventType, eventDataType:EventUnion, eventDataOffset:flatbuffers.Offset):flatbuffers.Offset {
  EventLog.startEventLog(builder);
  EventLog.addTimestamp(builder, timestamp);
  EventLog.addEventType(builder, eventType);
  EventLog.addEventDataType(builder, eventDataType);
  EventLog.addEventData(builder, eventDataOffset);
  return EventLog.endEventLog(builder);
}
}
